package com.jic.veteran.service.impl;

import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageHelper;
import com.jic.veteran.component.VeteranSecurityContext;
import com.jic.veteran.dao.AlumniEnterpriseAdminMapper;
import com.jic.veteran.dto.AlumniAddEnterpriseParam;
import com.jic.veteran.dto.AlumniAddNewsParam;
import com.jic.veteran.mapper.AlumniEnterpriseInformationMapper;
import com.jic.veteran.model.*;
import com.jic.veteran.service.AlumniEnterpriseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 学校信息Service实现类
 * Created by mars on 2021/11/24.
 */
@Slf4j
@Service
public class AlumniEnterpriseServiceImpl implements AlumniEnterpriseService {

    @Autowired
    private AlumniEnterpriseAdminMapper alumniEnterpriseAdminMapper;

    @Autowired
    private AlumniEnterpriseInformationMapper alumniEnterpriseInformationMapper;

    /**
     * news 分页
     * @return
     */
    @Override
    public List<AlumniEnterpriseInformation> getPage(Integer pageSize, Integer pageNum, String enterpriseName, Integer status) {

        PageHelper.startPage(pageNum, pageSize);
        List<AlumniEnterpriseInformation> alumniEnterpriseInformation;

        AlumniEnterpriseInformationExample alumniEnterpriseInformationExample = new AlumniEnterpriseInformationExample();
        AlumniEnterpriseInformationExample.Criteria criteria = alumniEnterpriseInformationExample.createCriteria();

        if(status != 3){
            criteria.andStatusEqualTo(status);
        }
        if(enterpriseName.length() > 0){
            criteria.andEnterpriseNameLike("%"+enterpriseName+"%");
        }
        alumniEnterpriseInformationExample.setOrderByClause("create_time desc");
        alumniEnterpriseInformation = alumniEnterpriseInformationMapper.selectByExampleWithBLOBs(alumniEnterpriseInformationExample);
        return alumniEnterpriseInformation;


    }

    @Override
    public int upEnterpriseStatus(Integer id, Integer status) {
        return alumniEnterpriseAdminMapper.upEnterpriseStatus(id,status);
    }

    @Override
    public int addEnterprise(AlumniAddEnterpriseParam alumniAddEnterpriseParam) {

        return alumniEnterpriseAdminMapper.addEnterprise(alumniAddEnterpriseParam,
                VeteranSecurityContext.getUserName(),
                DateUtil.date());
    }

    @Override
    public int aditEnterprise(Integer id, AlumniAddEnterpriseParam alumniAddEnterpriseParam) {

        return alumniEnterpriseAdminMapper.aditEnterprise(id,
                alumniAddEnterpriseParam,
                VeteranSecurityContext.getUserName(),
                DateUtil.date());
    }

    @Override
    public int deleteEnterprise(Integer id) {
        return alumniEnterpriseInformationMapper.deleteByPrimaryKey(id.longValue());

    }
}
